package com.dblibrary;

import java.util.ArrayList;

import com.dblibrary.DoListOpenHelper.DoListColumns;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

public abstract class DaoClass {

	public static final int FLAG_MODE_YESTERDAY = 0;
	public static final int FLAG_MODE_TODAY = 0x1;
	public static final int FLAG_MODE_TOMMOROW = 0x2;
	public static final int FLAG_MODE_LATER = 0x3;

	public static final int CN_IMPORTANCE_red = 0;
	public static final int CN_IMPORTANCE_cryon = 1;
	public static final int CN_IMPORTANCE_green = 2;

	public boolean dailyUpdate() {
		DoListOpenHelper dbOpen = new DoListOpenHelper(mContext);
		SQLiteDatabase db = dbOpen.getWritableDatabase();
		ContentValues values = new ContentValues();
		
		values.put(DoListColumns.CN_DAY, "later");
		db.update(DoListColumns.TABLE_NAME, values, "day=?",
				new String[] { "yesterday" });
		values = new ContentValues();
		
		values.put(DoListColumns.CN_DAY, "yesterday");
		db.update(DoListColumns.TABLE_NAME, values, "day=?",
				new String[] { "today" });
		values = new ContentValues();
		
		values.put(DoListColumns.CN_DAY, "today");
		db.update(DoListColumns.TABLE_NAME, values, "day=?",
				new String[] { "tomorrow" });
		Log.d("Ahn", "situation 3 :");
		db.close();
		dbOpen.close();
		
		return false;
	}

	public abstract boolean insert(String inputString, int colorFlag);

	public boolean delete(int dbid) {
		DoListOpenHelper dbOpen = new DoListOpenHelper(mContext);
		SQLiteDatabase db = dbOpen.getWritableDatabase();
		db.delete(DoListColumns.TABLE_NAME, "_id=" + dbid, null);
		db.close();
		dbOpen.close();
		return false;
	}

	public abstract boolean modify();

	public abstract boolean moveTo();

	public abstract boolean deleteAll();

	public abstract ArrayList<Bundle> select();

	public abstract ArrayList<Bundle> selectAll(int mHurryModeFlag);

	protected Context mContext;

	protected DaoClass(Context con) {
		mContext = con;

	}

	/**
	 * Do not use Constructor. DaoClass.getInstance
	 * 
	 * @param mCon
	 *            // Context
	 * @param mDayModeFlag
	 *            // DayFlag integer
	 * @return
	 */
	public static DaoClass getInstance(Context mCon, int mDayModeFlag) {
		if (FLAG_MODE_YESTERDAY == mDayModeFlag) {
			return new YesterdayDao(mCon);
		} else if (FLAG_MODE_TODAY == mDayModeFlag) {
			return new TodayDao(mCon);
		} else if (FLAG_MODE_TOMMOROW == mDayModeFlag) {
			return new TomorrowDao(mCon);
		} else {
			return new LaterDao(mCon);
		}
	}

}
